package com.example.yuncang.common;

import com.example.yuncang.entity.User;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result {
    private int code;
    private String msg;
    private Long total;
    private Object data;

    public  static Result fail(){

        return  result(400,"失败",0L,null);
    }
    public static Result suc(Object data){
        return  result(200,"成功",0L,data);

    }
    public static Result suc(){
        return  result(200,"成功",0L,null);

    }

    public static Result suc(List<User> data, Long total){
        return  result(200,"成功",total,data);

    }
    private static Result result(int code, String msg, Long total, Object data) {
        Result res = new Result();
        res.setData(data);
        res.setMsg(msg);
        res.setCode(code);
        res.setTotal(total);
        return res;
    }
}

